#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File        :   454.四数相加II.py    
@Contact     :   lhouctcs@163.com
@License     :   MIT
@Time        :   2023/2/7 21:41
@Author      :   lhou 
@Version     :   0.1.0
@Description :
"""
from typing import List


# import lib
class Solution:
    def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:
        dic = dict()
        count = 0
        for i in nums1:
            for j in nums2:
                s = i + j
                if s in dic:
                    dic[s] += 1
                else:
                    dic[s] = 1

        for i in nums3:
            for j in nums4:
                s = 0 - i - j
                if s in dic:
                    count += dic[s]
        return count
